<template>
    <div class="newsinfo-container">
        <h3 class="title">{{newsinfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间：{{ newsinfo.add_time | dateFormat }}</span>
            <span>点击：{{ newsinfo.click }}次</span>
        </p>
        <hr>
        <div class="content" v-html="newsinfo.content"></div>
        <cmt-box :id="newsid"></cmt-box>
    </div>
</template>
<script>
import { Toast } from 'mint-ui'
import comment from '../../subcomponents/comment.vue'
export default {
    data(){
        return {
            id: this.$route.params.id, //将url上传过来的id值挂载在data上，方便以后调用
            newsid: 1,
            newsinfo: {}
        }
    },
    created(){
        this.getNewsInfo()
    },
    methods: {
        getNewsInfo(){
            this.$http.get('/api/news').then((resp)=>{
                resp = resp.body
                if(resp.errno == 0){
                    this.newsinfo = resp.data[this.id - 1]
                }
                else{
                    Toast('获取新闻详情数据失败')
                }
            })
        }
    },
    components:{
        'cmt-box':comment
    }
}
</script>
<style lang="scss">
.newsinfo-container{
    padding: 0 4px;
    .title{
        font-size: 16px;
        text-align: center;
        color: red;
        margin: 15px 0;
    }
    .subtitle{
        color: #226aff;
        display: flex;
        justify-content: space-between;
    }
    .content{
        img{
            width: 100%;
            height: 100; 
            // 这样可能图片还是不能全部展示，需要将scoped去掉
        }
    }
}

</style>